package BOOK;

/**
 * Creat with IntelliJ IDEA
 * Description:书单
 * User:WZW
 * Date:2021-11-27
 * Time:17:51
 */
public class BookList {
    private Book[] books = new Book[10];
    private int usedSize;

    public BookList() {
        books[0] = new Book("高等数学（第七版）（上册）","同济大学数学系","高等教育出版社",38.60f);
        books[1] = new Book("小王子","(法) 圣埃克苏佩里、郑克鲁译","浙江工商大学出版社",22.10f);
        books[2] = new Book("数学之美 第三版","吴军","人民邮电出版社", 66.1f);
        usedSize = 3;
    }

    //查找图书，返回图书在BookList中的位置
    public int search(String name){
        int i = 0;
        while(books[i]!=null){
            if(books[i].getName().equals(name)){
                return i;
            }
            i++;
        }
        return -1;//找不到
    }

    //查找index位置上的书
    public Book getIndex(int index){
        return this.books[index];
    }

    //增加图书
    public void setBooks(int index, Book book) {
        this.books[index] = book;
    }

    public int getUsedSize() {
        return usedSize;
    }

    public void setUsedSize(int usedSize) {
        this.usedSize = usedSize;
    }

    public void display(){
        for (int i = 0; i < usedSize; i++) {
            System.out.println(books[i]);
        }
    }
}
